package com.example.carrierapp.ui.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.ListView
import com.example.carrierapp.ui.adapter.CommonAdapter
import com.example.carrierapp.viewmodel.itemmodel.ItemGoodsSourceModel
import com.example.lb.fingerdemo.R

class AutoListView : ListView {

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

    init {
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val expandSpec = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE shr 2, View.MeasureSpec.AT_MOST)
        super.onMeasure(widthMeasureSpec, expandSpec)
    }

    var address: MutableList<ItemGoodsSourceModel.Address>? = null
        set(value) {
            field = value
            value?.let {
                if (it.isNotEmpty())
                    adapter = CommonAdapter(context, R.layout.item_goods_source_midway, it)
            }
        }

}
